//
//  CZWelcomeViewController.swift
//  SinaWeiBo
//
//  Created by 刘幼寒 on 5/21/16.
//  Copyright © 2016 刘幼寒. All rights reserved.
//

import UIKit
import SnapKit

class CZWelcomeViewController: UIViewController
{

    override func viewDidLoad()
    {
        super.viewDidLoad()
        
        prepareUI()
    }
    
    override func viewDidAppear(animated: Bool)
    {
        super.viewDidAppear(animated)
        moveAnimation()
    }
    
    //移动动画
    private func moveAnimation()
    {
        UIView.animateWithDuration(3, delay: 0, usingSpringWithDamping: 0.5, initialSpringVelocity: 0, options: UIViewAnimationOptions(rawValue: 0), animations: { () -> Void in
            self.iconView.snp_updateConstraints(closure: { (make) -> Void in
                make.bottom.equalTo(self.view.snp_bottom).offset(-(UIScreen.mainScreen().bounds.height - 160))
            })
            self.view.layoutIfNeeded()
            }) { (_) -> Void in
                CZprint(items: "动画完成")
        }
       
                
       
    }
    
    private func prepareUI()
    {
        //self.view添加子控件
        self.view.addSubview(bkgView)
        self.view.addSubview(iconView)
        self.view.addSubview(messageLabel)
        //添加约束
        bkgView.snp_makeConstraints { (make) -> Void in
            //填充父控件
            make.edges.equalTo(self.view)
        }
        
        //头像
        iconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(self.view.snp_centerX)//当要约束的约束和参照的约束一样的时候，参照的约束可以省略（snp_centerX）
            make.bottom.equalTo(self.view.snp_bottom).offset(-160)
            
        }
        //消息label
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView)
            make.top.equalTo(iconView.snp_bottom).offset(16)
        }
        
        
    }
    
    //MARK: - 懒加载
    ///背景
    private lazy var bkgView: UIImageView = UIImageView(image: UIImage(named: "ad_background"))
    
    ///头像
    private lazy var iconView: UIImageView = {
        let iconview = UIImageView(image: UIImage(named: "avatar_default_big"))
        
        iconview.layer.cornerRadius = 42.5
        iconview.layer.masksToBounds = true
        
        
        return iconview
    }()
    
    //消息label
    private lazy var messageLabel: UILabel = {
        let label = UILabel()
        //设置label
        label.text = "欢迎归来"
        label.textColor = UIColor.blackColor()
        label.font = UIFont.systemFontOfSize(15)
        label.sizeToFit()
        
        return label
    }()

    

}
